#import "BaseNavigateionViewController.h"
#import "BaseViewController.h"

@interface BaseNavigateionViewController ()<UINavigationControllerDelegate>

@end

@implementation BaseNavigateionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    __weak typeof(self) weakself = self;
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.delegate = (id)weakself;
    }
}


-(void)configCustomNavigationBar{
    if (@available(iOS 13.0, *)) {
        UINavigationBarAppearance *app = [[UINavigationBarAppearance alloc] init];
        [app configureWithDefaultBackground];
        [app setTitleTextAttributes: @{
            NSForegroundColorAttributeName: [UIColor blackColor],
            NSFontAttributeName: [UIFont systemFontOfSize:17 weight:UIFontWeightRegular]
        }];
        
        app.backgroundColor = UIColor.whiteColor;
        
        [self.navigationBar setScrollEdgeAppearance:app];
        [self.navigationBar setStandardAppearance:app];
        
        self.navigationBar.standardAppearance.backgroundColor = [UIColor whiteColor];
        self.navigationBar.standardAppearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
        self.navigationBar.standardAppearance.shadowColor = [UIColor clearColor];
        self.navigationBar.scrollEdgeAppearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
        self.navigationBar.scrollEdgeAppearance.shadowColor = [UIColor clearColor];
    } else {
        self.navigationBar.translucent = NO;
        [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
        [self.navigationBar setShadowImage:[UIImage new]];//去掉阴影线
        [self.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                    [UIColor blackColor],
                                                    NSForegroundColorAttributeName,
                                                    [UIFont systemFontOfSize:17 weight:UIFontWeightRegular],
                                                    NSFontAttributeName,
                                                    nil]
        ];
    }
}


#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    if ([self.visibleViewController isKindOfClass:[BaseViewController class]]) {
        BaseViewController *base = (BaseViewController *)self.visibleViewController;
        if (base.closeSilder) {
            return NO;
        }
    }
    
    if (gestureRecognizer == self.interactivePopGestureRecognizer) {
        // 屏蔽调用rootViewController的滑动返回手势
        if (self.viewControllers.count < 2 || self.visibleViewController == [self.viewControllers objectAtIndex:0]) {
            return NO;
        }
    }
    
    return YES;
}

@end
